using UnityEngine;

namespace UnityX
{
    public static partial class Notification
    {
        /// <summary>
        /// 默认样式
        /// </summary>
        public static NotificationStyle defaultStyle = new NotificationStyle(new Color(0, 0, 0, 0.8f), Color.white, Color.green);
        /// <summary>
        /// 设置最大显示消息数量
        /// </summary>
        public static int maxShowCount
        {
            get
            {
                return panel.maxShowCount;
            }
            set
            {
                panel.maxShowCount = value;
                panel.Create();
                panel.SetSize();
            }
        }
        /// <summary>
        /// 设置顶部距离,数值为屏幕高度百分比值(0-100)
        /// </summary>
        public static float topDistanceHeightPercentage
        {
            get
            {
                return panel.topDistanceHeightPercentage;
            }
            set
            {
                panel.topDistanceHeightPercentage = value;
                panel.SetSize();
            }
        }

        private static NotificationPanel panel;

        static Notification()
        {
            GameObject gameObject = new GameObject("_X_Notification_X_");
            gameObject.hideFlags = HideFlags.HideInHierarchy;
            Object.DontDestroyOnLoad(gameObject);
            Canvas cv = gameObject.AddComponent<Canvas>();
            cv.renderMode = RenderMode.ScreenSpaceOverlay;
            cv.sortingOrder = 32765;
            panel = gameObject.AddComponent<NotificationPanel>();
        }

        /// <summary>
        /// 显示通知信息
        /// </summary>
        /// <param name="text">显示文字内容</param>
        public static void Show(string text)
        {
            panel.Add(text, defaultStyle, 5);
        }
        /// <summary>
        /// 显示通知信息
        /// </summary>
        /// <param name="text">显示文字内容</param>
        /// <param name="duration">显示持续时间（秒）</param>
        public static void Show(string text, float duration)
        {
            panel.Add(text, defaultStyle, duration);
        }
        /// <summary>
        /// 显示通知信息
        /// </summary>
        /// <param name="text">显示文字内容</param>
        /// <param name="iconColor">图标颜色</param>
        public static void Show(string text, Color iconColor)
        {
            NotificationStyle style = new NotificationStyle(defaultStyle);
            style.iconColor = iconColor;
            style.iconTexture = null;
            panel.Add(text, style, 5);
        }
        /// <summary>
        /// 显示通知信息
        /// </summary>
        /// <param name="text">显示文字内容</param>
        /// <param name="iconTexture">图标图片</param>
        public static void Show(string text, Texture2D iconTexture)
        {
            NotificationStyle style = new NotificationStyle(defaultStyle);
            style.iconColor = Color.white;
            style.iconTexture = iconTexture;
            panel.Add(text, style, 5);
        }

        /// <summary>
        /// 显示通知信息
        /// </summary>
        /// <param name="text">显示文字内容</param>
        /// <param name="style">显示样式</param>
        public static void Show(string text, NotificationStyle style)
        {
            panel.Add(text, style, 5);
        }
        /// <summary>
        /// 显示通知信息
        /// </summary>
        /// <param name="text">显示文字内容</param>
        /// <param name="style">显示样式</param>
        /// <param name="duration">显示持续时间（秒）</param>
        public static void Show(string text, NotificationStyle style, float duration)
        {
            panel.Add(text, style, duration);
        }
        /// <summary>
        /// 清空通知信息
        /// </summary>
        public static void Clear()
        {
            panel.Clear();
        }
    }
}